package br.com.skolar.client.framework.view;

import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTMLTable;
import com.google.gwt.user.client.ui.HTMLTable.RowFormatter;

public abstract class DataGridWidget<T> extends DataWidget<T> {
	protected abstract String[] getHeaders();

	@Override
	protected HTMLTable createTable() {
		return new Grid();
	}

	@Override
	protected void clearTable() {
		((Grid) table).resize(0, 0);
	}

	@Override
	protected void setupHeaders() {
		String[] headers = getHeaders();
		((Grid) table).resize(data.size() + 1, headers.length);
		
		RowFormatter rf = table.getRowFormatter();
		rf.getElement(0).setClassName(DATAGRID_HEADER);
		for(int i=0; i<headers.length; i++)
			table.setHTML(0, i, headers[i]);
	}
}